package com.hanggold.netty.bt;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * TODO COMMENT.
 *
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-11-27 21:25
 * @since 1.0.0
 **/
@Slf4j
public class ByteBufDemo {
    
    public static void main(String[] args) throws InterruptedException {
    
        final ByteBuf buffer = Unpooled.buffer(100);
        log.debug("length: {}", buffer.capacity());
        
        for (int i = 0; i < 256; i++) {
            buffer.writeInt(i);
            TimeUnit.MILLISECONDS.sleep(10L);
            log.info("index {}", i + 1);
        }
        log.debug("length2: {}", buffer.capacity());
        
        while (buffer.isReadable()) {
            log.info("read content {}",buffer.readInt());
        }
        
        log.debug("end read ");
    }
}
